<template>
	<view class="tab_Bg">
		<view class="tab_box">
			<image src="/static/img/tabbarBG.png" mode="" class="full tabbarBG"></image>
			<view class="tab-left flex-ac flex-b">
				<view class="item flexmid-col"  @click.stop="changeTab(1)">
					<image class="image" :src="'/static/img/tab-home'+ ( tabIndex == 1 ? '-current' : '' ) + '.png'" mode=""></image>
					<view class="text" :class="{'sel': tabIndex == 1 }">首页</view>
				</view>
				<view class="item flexmid-col"  @click.stop="changeTab(2)">
					<image class="image" :src="'/static/img/tab-cate'+ ( tabIndex == 2 ? '-current' : '' ) + '.png'" mode=""></image>
					<view class="text" :class="{'sel': tabIndex == 2 }">分类</view>
				</view>
			</view>
			<!-- 中间logo -->
			<view class="middleItem flexmid-col"  @click.stop="changeTab(5)">
				<view class="logoBG flexmid-col">
					<image class="imageBG" src="/static/img/logo.png" mode=""></image>
				</view>
			</view>
			
			<view class="tab-right flex-ac flex-b">
				<view class="item flexmid-col"  @click.stop="changeTab(3)" style="position: relative;">
					<image class="image" :src="'/static/img/tab-cart'+ ( tabIndex == 3 ? '-current' : '' ) + '.png'" mode=""></image>
					<view class="text" :class="{'sel': tabIndex == 3 }">购物车</view>
					<view class="goodsNum" v-if="goodsNum>0">{{goodsNum}}</view>
				</view> 
				<view class="item flexmid-col"  @click.stop="changeTab(4)">
					<image class="image" :src="'/static/img/tab-my'+ ( tabIndex == 4 ? '-current' : '' ) + '.png'" mode=""></image>
					<view class="text" :class="{'sel': tabIndex == 4 }">我的</view>
				</view>
			</view>
		</view>
		<view :style="'height:' + botdis + 'rpx'" style="width: 100%; background: #fff;"></view>
	</view>
</template>

<script>
	export default {
		name: 'x-tab-bar',
		props: {
			tabIndex:{
				type: [Number,String],
				default: 1
			},
			goodsNum:{
				type: [Number,String],
				default: 0
			}
		},
		data() {
			return {
				botdis: this.$app.globalData.botDis, //苹果X底部兼容
			}
		},
		created:function(){
			this.tab_index = parseInt(this.tabIndex)
		},
		methods: {
			// 切换导航栏
			changeTab:function(n){
				if(n==1){
					this.$Jump.switchTab("/pages/index/index")
				}
				if(n==2){
					this.$Jump.switchTab("/pages/category/category")
				}
				if(n==3){
					this.$Jump.switchTab("/pages/cart/cart")
				}
				if(n==4){
					this.$Jump.switchTab("/pages/user/user")
				}
				if(n==5){
					this.$Jump.switchTab("/pages/mall/mall")
				}
			},
		}
	}
</script>

<style lang="scss">
	.tab_Bg{
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 9999;
		background-color: #fff;
		.tab_box{
			width: 100%;
			height: 110rpx;
			// padding: 0 35rpx;
			// box-shadow: 0px 0px 8px 3px rgba(0,0,0,0.05);
			position: relative;
			.middleItem{
				width: 110rpx;
				height: 110rpx;
				border-radius: 50%;
				background-color: #FFFFFF;
				box-shadow: 4px 4px 30px 4px rgba(0,0,0,0.08); 
				position: absolute;
				left: 50%;
				bottom: 46rpx;
				transform: translate(-50%,0);
				.logoBG{
					width: 94rpx;
					height: 94rpx;
					background: #DFB263;
					border-radius: 50%;
					.imageBG{
						width: 50rpx;
						height: 50rpx;
					}
				}
			}
			.tabbarBG{
				width: 100%;
				height: 100%;
			}
			.tab-left{
				width: 42%;
				position: absolute;
				left: 0;
				bottom: 0;
				padding: 0 35rpx;
			}
			.tab-right{
				width: 42%;
				position: absolute;
				right: 0;
				bottom: 0;
				padding: 0 35rpx;
			}
			.item{
				padding: 0 30rpx;
				height: 110rpx;
				.image{
					width: 40rpx;
					height: 40rpx;
				}
				.text{
					font-size: 20rpx;
					color: $uni-text-color-grey;
					margin-top: 8rpx;
				}
				.sel{
					color: pink;
				}
				.goodsNum{
					position: absolute;
					top: 10rpx;
					right: 25rpx;
					width: 28rpx;
					height: 28rpx;
					border-radius: 50%;
					font-size: 20rpx;
					color: #fff;
					line-height: 28rpx;
					text-align: center;
					background-color: red;
				}
			}
		}
	}
</style>
